<?php
		
		direct_url();
		$id=$_GET['id']; //string nha
		
		$db=new db;
		$db->connect();
		$id=mysql_real_escape_string($id);
		
		//-------------------------- GET TRUYEN ----------------
		$db->query("select * from anime_theloai where alias='".$id."'");
		if($db->num_rows()>0){
			
			$r1=$db->fetchOne();
			$db->close();
		
		
		
		$data['theloai']=$r1;
		$url=mangaf1_url_manga_theloai($r1['id'],$r1['alias']).'/';
		$og_url=mangaf1_url_manga_theloai($r1['id'],$r1['alias']);
		
		
		$data1['canonical']=mangaf1_url_manga_theloai($r1['id'],$r1['alias']);
		if(isset($_GET['page'])){
		$data1['canonical']=$data1['canonical']."/".$_GET['page'];
		}
		
		
		
		$where="";
		$order="";
		$title="";
		if(isset($_GET['ext'])){
			$url=mangaf1_url_manga_theloai($r1['id'],$r1['alias']).'/'.$_GET['ext'].'/';
			$og_url=mangaf1_url_manga_theloai($r1['id'],$r1['alias']).'/'.$_GET['ext'];
			 switch($_GET['ext']){
			 	case 'date': $order=' order by upload_time desc'; $title=' Mới Đăng '; break;
				case 'views': $order=' order by views desc'; $title=' Xem Nhiều '; break;
				case 'comments': $order=' order by comments desc'; $title=' Thảo luận nhiều '; break;
				case 'thanks': $order=' order by thanks desc'; $title=' Được Yêu Thích '; break;
				case 'sochapter': $order=' order by tongsoep desc'; $title=' Nhiều Tập '; break;
				case 'hoanthanh': $where=' and tinhtrang=1'; $title=' Full '; break;
			 }
		}
		
		
		$cache=new Cache;
		if($where){
		$sql ="select * from anime_theloai_fk where theloai_id=".$r1['id'].$where." order by anime_id desc";
		$sql2="select anime_id from anime_theloai_fk where theloai_id=".$r1['id'].$where;
		}else
		if($order){
		$sql ="select * from anime_theloai_fk where theloai_id=".$r1['id'].$order;
		$sql2="select anime_id from anime_theloai_fk where theloai_id=".$r1['id'];
		}else{
		$sql ="select * from anime_theloai_fk where theloai_id=".$r1['id']." order by anime_id desc";
		$sql2="select anime_id from anime_theloai_fk where theloai_id=".$r1['id'];
		}
		
		//echo $sql2;
		
		$pager = new Pagination($sql,24,4,$url,14000,'anime_2');
		$pager->setDebug(false);
		$data['info'] = $pager->paginate($cache,$sql2);
		$data['nav']	= $pager->renderFullNav();
		}
	
	
			//--------- SEO START ---------------
				
				if($r1['seo_title']!=''){$stitle=$r1['seo_title'];	}else{ $stitle="Danh sách Truyện Tranh ".$r1['name'];}
				if($r1['seo_keyword']!=''){$skeyword=$r1['seo_keyword'];	}else{ $skeyword=$r1['name'];}
				if($r1['seo_description']!=''){$sdes=$r1['seo_description'];	}else{ $sdes="Bạn đang xem danh sách Truyện tranh  ".$r1['name']." tiếng việt tại Truyencuatui";}
				
			//--------- SEO END ---------------
	
	
			$data1['og']='<link rel="canonical" href="'.$og_url.'" /><meta name="ROBOTS" content="INDEX, FOLLOW"/>';
			$data1[title]=web_title($stitle.$title);
			$data1['mota']=web_des($sdes.$title);
			$data1['keyword']=web_keyword("truyen tranh online,doc truyen tranh online,truyen tranh,truyen tieng viet,truyen tranh ".$skeyword);
			loadview('template/header2',$data1);
			loadview("anime/list_anime_theloai",$data);
			loadview('template/footer2');
			exit();
			
			
